package com.hmdp;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmdp.dto.Result;
import com.hmdp.entity.Shop;
import com.hmdp.mapper.ShopMapper;
import com.hmdp.service.IShopService;
import com.hmdp.utils.CacheClient;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

import static com.hmdp.utils.RedisConstants.CACHE_SHOP_KEY;

@SpringBootTest
@Service
public class shopquery  {



    @Resource
    private IShopService iShopService;

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void queryShopById(Long id) {



        String key = CACHE_SHOP_KEY + id;


         Shop shop = iShopService.getById(id);

        // 4.2 数据库中存在，写入Redis，并返回店铺数据
        stringRedisTemplate.opsForValue().set(key, JSONUtil.toJsonStr(shop));
    }

    public Shop queryById(Long id){
        return iShopService.getById(id);
    }


    @Test
    void name() {
        queryShopById(3L);
    }
}


